﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Device.Location;

namespace DataObjectsPhone
{
    public class CheckPoint
    {
        public int Id { get; set; }
        public Decimal Latitude { get; set; }
        public Decimal Longitude { get; set; }
        public String Name { get; set; }
        public String Address { get; set; }
        public String Description { get; set; }
        public String WikiLink { get; set; }
        public String OtherLink { get; set; }
        public Guid ChallengeId { get; set; }
        public String Picture { get; set; }
        public int Points { get; set; }
        public Boolean Done { get; set; }
        public int Accuracy { get; set; }

        public CheckPoint()
        {
            Done = false;
        }

        public bool CheckLocation(GeoCoordinate geoCoordinate, bool changeStatus = false)
        {
            var isUpdated = false;
            if (!Done && geoCoordinate != GeoCoordinate.Unknown)
            {
                if (Accuracy >= geoCoordinate.HorizontalAccuracy)
                {
                    var distance = geoCoordinate.GetDistanceTo(new GeoCoordinate((double)Latitude, (double)Longitude));
                    if(distance < Accuracy)
                    {                      
                        Done = changeStatus;
                        isUpdated = true;
                    }
                }                
            }
            return isUpdated;
        }
    }
}
